import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

// import { i18n } from '@/vue-i18n'

// const $t = i18n.global.t

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/components/Layout.vue'),
    children: [
      {
        path: '/',
        name: 'Index',
        component: () => import('@/pages/event-warn/index.vue'),
        meta: { title: '上海试制保密&安全监测', icon:'Stopwatch', auth: true, visiable: true, role: ['admin']}
      },
      {
        path: '/detail',
        name: 'Detail',
        component: () => import('@/pages/event-warn/detail.vue'),
        meta: { title: '上海试制保密&安全监测', icon:'Stopwatch', auth: true, visiable: true, role: ['admin']}
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/pages/login/index.vue'),
    meta: { title: '上海试制保密&安全监测', icon:'Stopwatch', auth: false, visiable: true, role: ['any']}
  },
]

const router = createRouter({
  history: createWebHashHistory('/'),
  routes
});

// 防止连续点击多次路由报错
const routerPush = router.push;
const routerReplace = router.replace;
// push
router.push = function push(location: any) {
  return routerPush.call(this, location).catch((err) => err)
}
// replace
router.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default router
